<template>
	<el-dialog :close-on-click-modal="false" :title="titleText" v-model="visible" :width="600" destroy-on-close
		@closed="$emit('closed')"
	>
		<el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm" label-width="100px" label-position="right">
			<el-form-item label="备注信息:" prop="remark">
				<el-input type="textarea" :rows="3" v-model="form.remark" placeholder="请输入备注信息" :maxlength="255" show-word-limit />
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="submit()">确 认</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			titleText: '备注',
			visible: false,
			isSaveing: false,
			form: {
				id: null,
				remark: "",
			},
			rules: {
				remark: [
					{ required: true, message: '请输入备注信息', trigger: 'blur' },
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(title){
			this.visible = true;
			if(title) {
				this.titleText = title
			}
			return this
		},
		setData(row){
			this.form.id = row.id
			this.form.remark = row.remark
		},
		async submit() {
			if (!await this.$refs.dialogForm.validate().catch(() => { return false })) {
                return false
            }

			try {
				this.isSaveing = true
				await this.$API.finance.log.remark.put(this.form).then(() => {
					this.visible = false
					this.$emit('success')
					this.$notify.success('保存成功')
				})
			} catch (err) {
				this.isSaveing = false;
			} finally {
				this.isSaveing = false;
			}
		},
	}
}
</script>

